/*
 * lib2Desa - Another 2D game library in C++
 * Copyright (C) 2009 Erivaldo Xavier de Lima Filho
 *
 * This program is free software and is distributed under GNU General Public License version 3. You can modify and/or redistribute
 * it under the terms of GPL version 3 or posterior version. This program comes with NO WARRANTY, for more details, see LICENSE,
 * or <http://www.gnu.org/licenses>.
 *
 * Contact info:
 *
 *	Erivaldo Xavier de Lima Filho, desadoc@gmail.com
 *
 */

#include "Core/WindowMessage.hpp"
#include "Core/KeyMessage.hpp"
#include "SDL/EventNotifier.hpp"

#include "SDL/SDL.h"

#ifndef _NO_NAMESPACE
namespace lib2Desa {
#endif

namespace SDL {

void EventNotifier::processEvents(void)
{
	SDL_Event e;
	shared_ptr<IEvent> evt;

	while(SDL_PollEvent(&e))
	{
		switch(e.type)
		{
			case SDL_QUIT:
			{
				evt = new Event<WindowMessage>(weak_ptr<GameObject>(),weak_ptr<GameObject>(),WindowMessage(WindowMessage::WM_CLOSE));
				events.push_back(evt);
			} break;
			case SDL_KEYDOWN:
			{
				evt = new Event<KeyMessage>(weak_ptr<GameObject>(),weak_ptr<GameObject>(),KeyMessage(KeyMessage::KMT_KEYDOWN, (KeyMessage::KMK_KEY) e.key.keysym.sym));
				events.push_back(evt);
			} break;
			case SDL_KEYUP:
			{
				evt = new Event<KeyMessage>(weak_ptr<GameObject>(),weak_ptr<GameObject>(),KeyMessage(KeyMessage::KMT_KEYUP, (KeyMessage::KMK_KEY) e.key.keysym.sym));
				events.push_back(evt);
			}
		}
	}
}

}

#ifndef _NO_NAMESPACE
}
#endif
